package main


import (
	"context"
	"flag"
	"fmt"
	"net/http"
	gw "grpc-test/pb"

	"github.com/grpc-ecosystem/grpc-gateway/runtime"
	"google.golang.org/grpc"
)

var (
	echoEndpoint = flag.String("echo_endpoint","localhost:50051","你的rpc服务器地址和端口")
)

func run()error{
	ctx := context.Background()
	ctx,cancel := context.WithCancel(ctx)
	defer cancel()
	
	mux := runtime.NewServeMux()
	opts := []grpc.DialOption{grpc.WithInsecure()}
	err := gw.RegisterHelloSVCHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts)

	if err != nil {
		return err
	}
	return http.ListenAndServe(":9090",mux)
}

func main(){
	if err:= run();err != nil{
		fmt.Println(err.Error())
	}
}
